package ptaTest5;


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

interface IntegerStack
{
	public  Integer push(Integer item);
	public  Integer pop();
	public  Integer peek();
	public  boolean empty();
	public  int size();
}


class ArrayListIntegerStack implements IntegerStack{
	private List<Integer> list;
	
	
	public ArrayListIntegerStack(){
		list = new ArrayList<Integer>();
	}
	

	@Override
	public Integer push(Integer item) {
	if(item == null)
		return null;
	list.add(item);
	return item;
	}

	@Override
	public Integer pop() {
		if(list.isEmpty()) 
			return null;
        int top=list.remove(list.size()-1);
        return top;
	}

	@Override
	public Integer peek() {
	     if(list.isEmpty())
	        	return null;
	        else 
	        	return list.get(list.size()-1);
	}

	@Override
	public boolean empty() {
		 if(list.isEmpty())
			 return true;
	     else 
	        	return false;
	}

	@Override
	public int size() {
		 return list.size();
	}
	
	public String toString() {
		return list.toString();
	}


	}

public class Test551 {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc=new Scanner(System.in);
		ArrayListIntegerStack stack = new ArrayListIntegerStack();
		int m=sc.nextInt();
		while(m--!=0){
			System.out.println(stack.push(sc.nextInt()));
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(stack);
		m=sc.nextInt();
		while(m--!=0){
			System.out.println(stack.pop());
		}
		System.out.println(stack.peek()+","+stack.empty()+","+stack.size());
		System.out.println(stack);
	}
}

